<?php
class CopyManager extends Manager
{
	const TABLE_NAME = 'egzemplarze';
	const TABLE_AVAIL_NAME = 'dostepne_egzemplarze';
	const OBJECT_NAME = 'Copy';
	const PK_NAME = 'id';

	public function getById($id)
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)
					->where('id = ?', $id);
		return $this->_fetchObject(self::OBJECT_NAME, $select);
	}

	public function getByIsbn($isbn)
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)
					->where('isbn = ?', $isbn);
		return $this->_fetchCollection(self::OBJECT_NAME, $select);
	}

	public function getAvailableByIsbn($isbn)
	{
		$select = $this->_db->select()->from(self::TABLE_NAME)
					->join(self::TABLE_AVAIL_NAME, 
						self::TABLE_AVAIL_NAME . '.id = ' . self::TABLE_NAME . '.id', self::TABLE_AVAIL_NAME . '.dostepny')
					->where(self::TABLE_NAME . '.isbn = ?', $isbn)
					->where(self::TABLE_AVAIL_NAME  . '.dostepny = ?', 1);
					
		return $this->_fetchCollection(self::OBJECT_NAME, $select);
	}
}